//
//  BDSettingTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/3/17.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDSettingTableViewCell.h"

@interface BDSettingTableViewCell ()

@property (nonatomic, strong) UIImageView *cu_imageView;
@property (nonatomic, strong) UIImageView *rightImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;

@end

@implementation BDSettingTableViewCell

- (void)configeWithDic:(NSDictionary *)dic{
    if (dic[@"image"]) {
        self.cu_imageView.hidden = NO;
        self.subTitleLabel.hidden = YES;
        [self.cu_imageView sd_setImageWithURL:[NSURL URLWithString:dic[@"image"]] placeholderImage:[UIImage imageNamed:@"avatar"] options:SDWebImageRetryFailed];
    }else if (dic[@"subTitle"]) {
        self.cu_imageView.hidden = YES;
        self.subTitleLabel.hidden = NO;
        self.subTitleLabel.text = dic[@"subTitle"];
    }
    self.titleLabel.text = dic[@"title"];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    self.titleLabel.textColor = [UIColor colorWithHexString:@"#4c4c4c"];
    self.titleLabel.left = 10;
    self.titleLabel.height = 15;
    self.titleLabel.width = [self.titleLabel.text widthWithFont:self.titleLabel.font];;
    self.titleLabel.centerY = self.height / 2.0;
    
    self.rightImageView.size = CGSizeMake(10, 10);
    self.rightImageView.right = self.width - 10;
    self.rightImageView.centerY = self.titleLabel.centerY;
    self.rightImageView.image = [UIImage imageNamed:@"righ"];
    
    self.subTitleLabel.font = [UIFont systemFontOfSize:13];
    self.subTitleLabel.textColor = [UIColor colorWithHexString:@"#4c4c4c"];
    self.subTitleLabel.width = [self.subTitleLabel.text widthWithFont:self.subTitleLabel.font];
    self.subTitleLabel.right = self.rightImageView.left - 10;
    self.subTitleLabel.height = 15;
    self.subTitleLabel.centerY = self.height / 2.0;
    
    self.cu_imageView.size = CGSizeMake(60, 60);
    self.cu_imageView.right = self.subTitleLabel.right;
    self.cu_imageView.centerY = self.subTitleLabel.centerY;
    self.cu_imageView.layer.masksToBounds = YES;
    self.cu_imageView.layer.cornerRadius = 30;
    
    self.backgroundColor = [UIColor whiteColor];
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)subTitleLabel{
    if (!_subTitleLabel) {
        self.subTitleLabel = [[UILabel alloc] init];
        [self addSubview:_subTitleLabel];
    }
    return _subTitleLabel;
}

- (UIImageView *)cu_imageView{
    if (!_cu_imageView) {
        self.cu_imageView = [[UIImageView alloc] init];
        [self addSubview:_cu_imageView];
    }
    return _cu_imageView;
}

- (UIImageView *)rightImageView{
    if (!_rightImageView) {
        self.rightImageView = [[UIImageView alloc] init];
        [self addSubview:_rightImageView];
    }
    return _rightImageView;
}

@end
